package cn.stylefeng.guns.modular.inventory.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.service.BasicWarehouseService;
import cn.stylefeng.guns.modular.inventory.entity.MoveDiskDetailed;
import cn.stylefeng.guns.modular.inventory.model.params.MoveDiskDetailedParam;
import cn.stylefeng.guns.modular.inventory.service.MoveDiskDetailedService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 库存管理   表控制器
 */
@Controller
@RequestMapping("/moveDiskDetailed")
public class MoveDiskDetailedController extends BaseController {

    private String PREFIX = "/inventory/moveDiskDetailed";

    @Autowired
    private MoveDiskDetailedService moveDiskDetailedService;

    @Autowired
    private UserService userService;

    @Autowired
    private BasicWarehouseService basicWarehouseService;

    /**
     * 跳转到主页面
     */
    @RequestMapping("")
    public String index(Model model) {
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();
    	
    	//查询可选择仓库
    	model.addAttribute("basicWarehouseList", basicWarehouseService.findAvailableList(deptId,deliverId,user.getOperateId()));
        return PREFIX + "/moveDiskDetailed.html";
    }

    /**
     * 新增页面
     *
     * @author hu
     * @Date 2019-08-08
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/moveDiskDetailed_add.html";
    }

    /**
     * 编辑页面
     *
     * @author hu
     * @Date 2019-08-08
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/moveDiskDetailed_edit.html";
    }

    /**
     * 新增接口
     *
     * @author hu
     * @Date 2019-08-08
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(MoveDiskDetailedParam moveDiskDetailedParam) {
        this.moveDiskDetailedService.add(moveDiskDetailedParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author hu
     * @Date 2019-08-08
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(MoveDiskDetailedParam moveDiskDetailedParam) {
        this.moveDiskDetailedService.update(moveDiskDetailedParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author hu
     * @Date 2019-08-08
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(MoveDiskDetailedParam moveDiskDetailedParam) {
        this.moveDiskDetailedService.delete(moveDiskDetailedParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author hu
     * @Date 2019-08-08
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(MoveDiskDetailedParam moveDiskDetailedParam) {
        MoveDiskDetailed detail = this.moveDiskDetailedService.getById(moveDiskDetailedParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     * @author hu
     * @Date 2019-08-08
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(MoveDiskDetailedParam moveDiskDetailedParam,String condition ) {
    	User user = userService.getcurrentUser();
        return this.moveDiskDetailedService.findPageBySpec(moveDiskDetailedParam,condition,user.getDeptId(),user.getOperateId());
    }

    /**
     * 查询列表
     */
    @ResponseBody
    @RequestMapping("/querylist")
    public LayuiPageInfo querylist(MoveDiskDetailedParam moveDiskDetailedParam,String condition ) {
        return this.moveDiskDetailedService.querylistPageBySpec(moveDiskDetailedParam,condition);
    }

}


